
inputFile = "sample.input"

import sys

tokens = (
	'LPAREN', 'RPAREN', 'COMMA', 'NUMBER',
	)

# token
t_LPAREN = r'\('
t_RPAREN = r'\)'
t_COMMA = r','

def t_NUMBER(t): 
	r'\d+'
	try:
		t.value = int(t.value)
	except:
		print("Integer too large: %d", t.value)
		t.value = 0
	return t

# ignored
t_ignore = " \t\r"

def t_newline(t):
	r'\n+'
	t.lexer.lineno += len(t.value)

def t_error(t):
	print("Illegal charactor '%s'" % t.value[0])
	t.lexer.skip(l)


import ply.lex as lex
lex.lex()

# parsing rules
def p_statement_list1(t):
	'list : LPAREN seq RPAREN'
	t[0] = '( '+str(t[2])+')' 

def p_statement_list2(t):
	'list : LPAREN RPAREN'
	t[0] = "( ) " 

def p_statement_seq1(t):
	'seq  : elt COMMA seq'
	t[0] = str(t[1])+', '+str(t[3])

def p_statement_others(t):
	'''seq : elt
	   elt : list
	'''
	t[0] = t[1]

def p_statment_number(t):
	'elt : NUMBER'
	t[0] = str(t[1])

def p_error(t):
	print("----Syntax error!----")
	sys.exit(1)

import ply.yacc as yacc
yacc.yacc()


f = open(inputFile, 'r')
s = f.read()
f.close()
print yacc.parse(s)

